﻿using System;
using System.ServiceProcess;
using System.Threading;
using SleepManagement.Controllers;

namespace SleepManagement
{
    public partial class SleepManagementService : ServiceBase
    {
        private ISleepManager sleepManager;

        public SleepManagementService(ISleepManager sleepManager)
        {
            if (sleepManager == null) throw new ArgumentNullException("sleepManager");
            this.sleepManager = sleepManager;

            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            try
            {
                var dreamBounds = sleepManager.ReadDreamValues();
                sleepManager.CheckInput(ref dreamBounds);               
                new Thread(() => sleepManager.DoWork(dreamBounds)).Start();
            }
            catch (Exception e)
            {
                CustomLogManager.LogException(e);
                throw;
            }
            
        }
        

        

    }
}
